package com.ly.algorithm.offerpointer;

/**
 * @Classname Offer
 * @Description TODO
 * @Date 2021/1/27 12:53
 * @Author 冷心影翼
 */
public class Offer18 {

    public static void main(String[] args) {
        Solution18 solution18 = new Solution18();
        ListNode init = ListNode.init(new int[]{4,5});
        solution18.deleteNode(init,4).printRes();
    }

}


class Solution18 {
    public ListNode deleteNode(ListNode head, int val) {
        if(head!=null && head.val == val) {
            head = head.next;
        }
        ListNode cur = head;
        while (cur!=null) {
            if(cur.next!=null && cur.next.val == val) {
                cur.next = cur.next.next;
            }
            cur = cur.next;
        }
        return head;
    }
}